package com.zhentao.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.model.pojo.user.ChargeUser;
import com.zhentao.model.pojo.user.yichang.ChargeUserExpeciton;
import com.zhentao.service.ChargeUserExpecitonService;
import com.zhentao.mapper.ChargeUserExpecitonMapper;
import com.zhentao.user.ChargeUserThreadUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import static com.zhentao.model.common.enums.AppHttpCodeEnum.CHARGE_USER_CODE_ERROR;

/**
* @author Wl177
* @description 针对表【charge_user_expeciton】的数据库操作Service实现
* @createDate 2024-12-26 09:43:05
*/
@Service
public class ChargeUserExpecitonServiceImpl extends ServiceImpl<ChargeUserExpecitonMapper, ChargeUserExpeciton>
    implements ChargeUserExpecitonService{

    @Resource
    private ChargeUserExpecitonMapper chargeUserExpecitonMapper;
    @Override
    public ResponseResult sentException(ChargeUserExpeciton userExpeciton) {
        //获取当前登录对象
        ChargeUser user = ChargeUserThreadUtils.getChargeUserThreadLocal();
        //检查参数
        if (userExpeciton == null) {
            return ResponseResult.errorResult(CHARGE_USER_CODE_ERROR);
        }
        userExpeciton.setUserId(user.getId().intValue());
        userExpeciton.setCreateTime(new Date());
        int insert = chargeUserExpecitonMapper.insert(userExpeciton);
        return ResponseResult.okResult("发送成功");
    }

    @Override
    public List<ChargeUserExpeciton> getExceptionList() {
        List<ChargeUserExpeciton> chargeUserExpecitons = chargeUserExpecitonMapper.selectList(null);
        return chargeUserExpecitons;
    }

    @Override
    public ResponseResult updateException(ChargeUserExpeciton exception) {
        System.out.println(exception);
        //判断参数
        if (exception == null) {
            return ResponseResult.errorResult(CHARGE_USER_CODE_ERROR);
        }
        chargeUserExpecitonMapper.updateException(exception);
        return ResponseResult.okResult("处理成功");
    }
}




